from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from model.ModCompanyOperator import CompanyOperator, companyOperatorSchema
from database import Session


def get_operator_info(session, openid):
    company_operators = session.query(CompanyOperator).filter(CompanyOperator.openid == openid).one_or_none()
    return JSONResponse(companyOperatorSchema.dump(company_operators, many=False).data)


def get_all_operators(session):
    operators = session.query(CompanyOperator).order_by(CompanyOperator.departmentid.desc()).all()
    return companyOperatorSchema.dump(operators, many=True).data
